package STUDENT.TranMinhVu.OOPS.ArrayExercises.BaiTapQuanLySachThuVien;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Models {
	BangQLMuonSach bql = new BangQLMuonSach();
	BanDoc bd = new BanDoc();
	Sach sach = new Sach();
	List<BangQLMuonSach> dsbql = new ArrayList<BangQLMuonSach>();
	public List<Sach> booklist = new ArrayList<Sach>();
	public List<BanDoc> readerlist = new ArrayList<BanDoc>();
	public boolean Kiemtrabandoc(BangQLMuonSach bql,List<Sach> booklist,List<BanDoc> readerlist){
		for (BanDoc bd : readerlist) {
			if (bql.getMabandoc() == bd.getMaBanDoc()&&bql.getTenbandoc().equals(bd.getHoten())) {
				return true;
			}
		}
		return false;
	}
	
	public boolean Kiemtrasach(BangQLMuonSach bql,List<Sach> booklist,List<BanDoc> readerlist){
		for(int i=0; i<bql.getSodausach();i++){
			for (Sach b : booklist) {
				if (bql.getMasachmuon()[i] == b.getMasach()&&bql.getDausach()[i].equals(b.getTensach())) {
					return true;
				}
			}
		}
		return false;
	}
	
	public boolean Kiemtradausach(BangQLMuonSach bql){
		if (bql.getSodausach()>5)
			return false;
		else
			return true;
	}
	
	public boolean Kiemtrasosach(BangQLMuonSach bql){
		for (int sosachmuon : bql.getSosachmuon()) {
			if(sosachmuon>3){
				return false;
			}
		}return true;
	}
	
	public void BookInput(List<Sach> booklist){
		int i = 0;
		int k= 10000;
		System.out.println("Moi nhap danh sach dau sach");
		String[] chuyenNganh = {"Khoa học tự nhiên", "Văn học – Nghệ thuật", "Điện tử Viễn thông", "Công nghệ thông tin"}; 
		while (i>=0){			
			Scanner sc = new Scanner(System.in);
			System.out.println("Ten Sach");
			String tensach = sc.nextLine();
			System.out.println("Ten Tac gia");
			String tentacgia = sc.nextLine();
			System.out.println("Nam xuat ban");
			int namxuatban = sc.nextInt();
			sc.nextLine();
			System.out.println("Chuyen nganh: " + "0-Khoa học tự nhiên. 1-Văn học - Nghệ thuật. "
					+ "2-Điện tử viễn thông 3-Công nghệ thông tin");
			String chuyennganh=chuyenNganh[sc.nextInt()];
			sc.nextLine();
			booklist.add(new Sach(k+i, tensach, tentacgia, namxuatban, chuyennganh));
			System.out.println("Nhap -1 de thoat\nNhap 0 de tiep tuc");
			if(sc.nextInt()==-1)break;
			i++;	
		}
	}
	
	public void BookOutput(List<Sach> booklist){
		for (Sach sach : booklist) {
			System.out.println(sach);	
		}
	}
	
	public void ReaderInput(List<BanDoc> readerlist){
			int i = 0;
			int k = 10000;
			String[] loaiBanDoc = {"Sinh Viên", "Cao Học Viên", "Giảng Viên"};
			while (i>=0){
			Scanner sc = new Scanner(System.in);
			System.out.println("Ho Ten");
			String hoten = sc.nextLine();
			System.out.println("Dia Chi");
			String diachi = sc.nextLine();
			System.out.println("So Dien Thoai");
			int sodienthoai = sc.nextInt();
			sc.nextLine();
			System.out.println("Loai Ban Doc: "+ "0 - Sinh Vien; 1 - Cao Học Viên; 2 - Giảng Viên");
			String loaibandoc = loaiBanDoc[sc.nextInt()];
			sc.nextLine();
			readerlist.add(new BanDoc(k+i, hoten, diachi, sodienthoai, loaibandoc));
			System.out.println("Nhap -1 de thoat\nNhap 0 de tiep tuc");
			if(sc.nextInt()==-1)break;
			i++;	
		}
	}
	
	public void ReaderOutput(List<BanDoc> readerlist){
		for (BanDoc banDoc : readerlist) {
			System.out.println(banDoc);
		}	
	}
	
	public BangQLMuonSach FindReader(List<BangQLMuonSach> dsbql){
		Scanner sc = new Scanner(System.in);
		System.out.println("Moi nhap ten ban doc can tim");
		String tenbandoc = sc.nextLine();
		for (BangQLMuonSach bql : dsbql) {
			if(tenbandoc.equals(bql.tenbandoc))
				return bql;
		}
		return null;
	}
}